//
//  DTCalendarView.m
//  JunZeWristband
//
//  Created by Kendama on 2017/9/13.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "DTCalendarView.h"

@implementation DTCalendarView
- (instancetype)initWithOrigin:(CGPoint)origin Width:(CGFloat)width Height:(CGFloat)height Type:(XTDirectionType)type Color:(UIColor *)color
{
    if ([super initWithOrigin:origin Width:width Height:height Type:type Color:color])
    {
        [self.backGoundView addSubview:self.calendarView];
        [self masLayoutSubview];
        self.backGoundView.layer.cornerRadius = 4;
        self.backGoundView.clipsToBounds = YES;
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
    }
    return self;
}

+ (void)showCalendarViewByDelegate:(id)obj
{
    DTCalendarView *popView = [[DTCalendarView alloc] initWithOrigin:CGPointMake(ScreenWidth/2, ScreenHeight) Width:ScreenWidth Height:ScreenWidth Type:XTTypeOfDownCenter Color:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8]];
    popView.delegate = obj;
    [popView popView];
}

- (void)masLayoutSubview
{
    [self.calendarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.backGoundView);
    }];
}

- (DAYCalendarView *)calendarView
{
    if(!_calendarView)
    {
        _calendarView = [[DAYCalendarView alloc]init];
        _calendarView.backgroundColor = [UIColor whiteColor];
        [_calendarView addTarget:self action:@selector(calendarViewDidChange:) forControlEvents:UIControlEventValueChanged];
    }
    return _calendarView;
}

- (void)calendarViewDidChange:(id)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(selectDate:)]) {
        [self.delegate selectDate:self.calendarView.selectedDate];
        [self removeFromSuperview];
    }

}

@end
